var app = getApp();
//获得

var MyRequest = require("../../utils/MyRequest.js");
var Global = require("../../Global.js");

Page({
    Presenter:{
        init:function(that){
            var data={
                action:"info",
                id:that.data.id
            };
            MyRequest.MyGetWithToast("OrderInfo", that, that.Binder.init, data);
        }
    },
    Binder:{
        init:function(result,that){
            that.setData({
                orderInfo: result.data.data
            });
        }
    },
    onLoad:function(options){
        this.setData({
            id:options.id
        });
        this.Presenter.init(this);
    },
    onReady:function(){
         
    },
    toCall:function(){
        wx.makePhoneCall({
            phoneNumber: '4006059144',
            success: function(res) {
                // success
            }
        })
    },
    toSuggestion:function(){
        wx.navigateTo({
            url: '/pages/suggestion/suggestion'
        })
    },
    toComment:function(){
        var params = "?orderNo="+this.data.orderInfo.orderNo;
        params += "&orderTime=";
        params += this.data.orderInfo.orderTime;
        params += "&id=";
        params += this.data.orderInfo.id;
        
        wx.navigateTo({
            url: '/pages/comment/comment'+params
        })
    },
    toPay:function(){
        console.log(this.data.orderInfo);
        var data = this.data.orderInfo;
        var userInfo = Global.getUserStorage();
        console.log(userInfo)

        var parameter = "?";
            parameter += "accountMoney=" + userInfo.money + "&";
            parameter += "freePrice=" + data.freePrice + "&";
            parameter += "goodsCount=" + data.goodsCount + "&";
            parameter += "orderId=" + data.orderId + "&";
            parameter += "orderNo=" + data.orderNo + "&";
            parameter += "orderTime=" + data.orderTime + "&";
            parameter += "totalPrice=" + data.totalPrice;
            wx.redirectTo({
                url: '/pages/pay/pay' + parameter,
            });
    }
    ,
    cancelOrder:function(){
        var user = Global.getUserStorage();
        var sign = Global.getUserSign();


        console.log(sign)
        var data={
                userId:user.id,
                userSign:sign,
                orderNo:this.data.orderInfo.orderNo
            };
   
            MyRequest.MyGetWithToast("CancelOrder", this, this.cancelOrderBack, data);
    },
    cancelOrderBack:function(result){
        //this.Presenter.init(this);
        var pages = getCurrentPages();
        var prePage = pages[pages.length - 2];
        prePage.Presenter.init(prePage);
        wx.navigateBack();

    },
     onPullDownRefresh: function () {
    wx.stopPullDownRefresh();
  }
});